package cate.game.pvp.throne.data.ko;

import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;

@NoteClass(value = "王座争霸-晋级赛-单个分组",detail = "胜者组败者组")
public class TBKoAdvanceGroup {

	@NoteField(value = "分组类型",detail = "1胜者组 2败者组")
	public int groupType;

	@NoteField("排行榜数据")
	public TBKoRank rank;

	@NoteField("轮次数据")
	public List<TBKoRound> rounds;

	public void initialize() {
		if (rank == null) {
			rank = new TBKoRank();
		}
		rank.initialize();
		if (rounds == null) {
			rounds = new ArrayList<>();
		}
		rounds.forEach(TBKoRound::initialize);
	}

	public TBKoAdvanceGroup(int groupType) {
		this.groupType = groupType;
	}

	public TBKoAdvanceGroup() {
	}

	/** 获取某一个回合的信息 */
	@JsonIgnore
	public TBKoRound getOrBuildRound(int round) {
		for (TBKoRound roundSPO : rounds) {
			if (roundSPO.round == round) {
				return roundSPO;
			}
		}
		TBKoRound roundPO = new TBKoRound(round);
		roundPO.initialize();
		rounds.add(roundPO);
		return roundPO;
	}

	@JsonIgnore
	public TBKoRound findRound(int round) {
		for (TBKoRound roundSPO : rounds) {
			if (roundSPO.round == round) {
				return roundSPO;
			}
		}
		return null;
	}


	public void clear(){
		this.rank.clear();
		this.rounds.clear();
	}

}
